

/*绑定关系模块功能测试*/

#include "../mqserver/mq_binding.hpp"
#include <gtest/gtest.h>


const std::string defaultfile = "./db/data.db";
xgmq::BindingManager::ptr bmp;


// 编写全局测试套件
class BindingTest : public testing::Environment
{
public:
    void SetUp() override
    {
        // 初始化环境
        bmp = std::make_shared<xgmq::BindingManager>(defaultfile);
    }
    void TearDown() override
    {
        // 清理环境
        bmp->clear();
    }
};

// 新增绑定关系的测试
TEST(binding_test, insert_test)
{
    bmp->bind("交换机1","队列1","实习");
    bmp->bind("交换机1","队列2","挣钱");
    bmp->bind("交换机1","队列3","去北京");
    bmp->bind("交换机2","队列4","实习");
    bmp->bind("交换机2","队列5","挣钱");
    bmp->bind("交换机2","队列6","去武功山");

    ASSERT_EQ(bmp->size(),6);
}
// 删除绑定关系测试
TEST(binding_test, delete_test)
{
    // bmp->removeQueueBinding("队列1");
    // bmp->removeQueueBinding("队列6");
    bmp->removeExchangeBinding("交换机2");
    ASSERT_EQ(bmp->size(),3);
}
// 获取绑定关系测试
TEST(queue_test, get_test)
{
    xgmq::Binding::ptr bp = bmp->getBinding("交换机1","队列3");
    ASSERT_NE(bp.get(),nullptr);//为空就不继续往下走了
    ASSERT_EQ(bp->exchange_name,std::string("交换机1"));
    ASSERT_EQ(bp->msgQueue_name,"队列3");
    ASSERT_EQ(bp->binding_key,"去北京");
}

int main(int argc, char *argv[])
{
    testing::InitGoogleTest(&argc, argv);
    // 添加全局测试套件
    testing::AddGlobalTestEnvironment(new BindingTest);
    int ret = RUN_ALL_TESTS();

    return 0;
}
